<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for c:\program files\python26\lib\ntpath</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>c:\program files\python26\lib\ntpath</b> :
            <span class='pc_cov'>13%</span>
        </h1>
        <h2 class='stats'>
            254 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>35 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>219 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>6 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='stm mis'>2</p>
<p class='pln'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='stm mis'>8</p>
<p class='stm mis'>9</p>
<p class='stm mis'>10</p>
<p class='stm mis'>11</p>
<p class='stm mis'>12</p>
<p class='pln'>13</p>
<p class='stm mis'>14</p>
<p class='pln'>15</p>
<p class='stm mis'>16</p>
<p class='pln'>17</p>
<p class='pln'>18</p>
<p class='pln'>19</p>
<p class='pln'>20</p>
<p class='pln'>21</p>
<p class='pln'>22</p>
<p class='pln'>23</p>
<p class='stm mis'>24</p>
<p class='stm mis'>25</p>
<p class='stm mis'>26</p>
<p class='stm mis'>27</p>
<p class='stm mis'>28</p>
<p class='stm mis'>29</p>
<p class='stm mis'>30</p>
<p class='stm mis'>31</p>
<p class='stm mis'>32</p>
<p class='stm mis'>33</p>
<p class='pln'>34</p>
<p class='stm mis'>35</p>
<p class='stm mis'>36</p>
<p class='pln'>37</p>
<p class='pln'>38</p>
<p class='pln'>39</p>
<p class='pln'>40</p>
<p class='pln'>41</p>
<p class='stm mis'>42</p>
<p class='pln'>43</p>
<p class='pln'>44</p>
<p class='pln'>45</p>
<p class='stm run hide_run'>46</p>
<p class='pln'>47</p>
<p class='pln'>48</p>
<p class='pln'>49</p>
<p class='pln'>50</p>
<p class='pln'>51</p>
<p class='pln'>52</p>
<p class='pln'>53</p>
<p class='pln'>54</p>
<p class='stm mis'>55</p>
<p class='pln'>56</p>
<p class='stm mis'>57</p>
<p class='stm mis'>58</p>
<p class='pln'>59</p>
<p class='pln'>60</p>
<p class='pln'>61</p>
<p class='pln'>62</p>
<p class='stm mis'>63</p>
<p class='pln'>64</p>
<p class='pln'>65</p>
<p class='pln'>66</p>
<p class='stm mis'>67</p>
<p class='stm mis'>68</p>
<p class='stm mis'>69</p>
<p class='stm mis'>70</p>
<p class='stm mis'>71</p>
<p class='pln'>72</p>
<p class='stm mis'>73</p>
<p class='pln'>74</p>
<p class='pln'>75</p>
<p class='pln'>76</p>
<p class='pln'>77</p>
<p class='pln'>78</p>
<p class='pln'>79</p>
<p class='pln'>80</p>
<p class='pln'>81</p>
<p class='stm mis'>82</p>
<p class='pln'>83</p>
<p class='stm mis'>84</p>
<p class='pln'>85</p>
<p class='pln'>86</p>
<p class='stm mis'>87</p>
<p class='pln'>88</p>
<p class='pln'>89</p>
<p class='stm mis'>90</p>
<p class='pln'>91</p>
<p class='stm mis'>92</p>
<p class='stm mis'>93</p>
<p class='pln'>94</p>
<p class='pln'>95</p>
<p class='stm mis'>96</p>
<p class='stm mis'>97</p>
<p class='stm mis'>98</p>
<p class='stm mis'>99</p>
<p class='pln'>100</p>
<p class='stm mis'>101</p>
<p class='stm mis'>102</p>
<p class='stm mis'>103</p>
<p class='stm mis'>104</p>
<p class='stm mis'>105</p>
<p class='stm mis'>106</p>
<p class='pln'>107</p>
<p class='stm mis'>108</p>
<p class='pln'>109</p>
<p class='pln'>110</p>
<p class='pln'>111</p>
<p class='pln'>112</p>
<p class='pln'>113</p>
<p class='stm mis'>114</p>
<p class='pln'>115</p>
<p class='stm mis'>116</p>
<p class='pln'>117</p>
<p class='pln'>118</p>
<p class='pln'>119</p>
<p class='pln'>120</p>
<p class='pln'>121</p>
<p class='stm mis'>122</p>
<p class='pln'>123</p>
<p class='pln'>124</p>
<p class='stm run hide_run'>125</p>
<p class='stm run hide_run'>126</p>
<p class='stm run hide_run'>127</p>
<p class='pln'>128</p>
<p class='pln'>129</p>
<p class='pln'>130</p>
<p class='stm mis'>131</p>
<p class='pln'>132</p>
<p class='pln'>133</p>
<p class='pln'>134</p>
<p class='pln'>135</p>
<p class='pln'>136</p>
<p class='pln'>137</p>
<p class='pln'>138</p>
<p class='stm mis'>139</p>
<p class='stm mis'>140</p>
<p class='stm mis'>141</p>
<p class='stm mis'>142</p>
<p class='pln'>143</p>
<p class='pln'>144</p>
<p class='pln'>145</p>
<p class='pln'>146</p>
<p class='stm mis'>147</p>
<p class='stm mis'>148</p>
<p class='stm mis'>149</p>
<p class='pln'>150</p>
<p class='stm mis'>151</p>
<p class='stm mis'>152</p>
<p class='stm mis'>153</p>
<p class='stm mis'>154</p>
<p class='stm mis'>155</p>
<p class='stm mis'>156</p>
<p class='pln'>157</p>
<p class='pln'>158</p>
<p class='pln'>159</p>
<p class='pln'>160</p>
<p class='pln'>161</p>
<p class='pln'>162</p>
<p class='pln'>163</p>
<p class='stm mis'>164</p>
<p class='pln'>165</p>
<p class='pln'>166</p>
<p class='pln'>167</p>
<p class='pln'>168</p>
<p class='pln'>169</p>
<p class='stm run hide_run'>170</p>
<p class='pln'>171</p>
<p class='stm run hide_run'>172</p>
<p class='stm run hide_run'>173</p>
<p class='stm run hide_run'>174</p>
<p class='stm run hide_run'>175</p>
<p class='pln'>176</p>
<p class='stm run hide_run'>177</p>
<p class='stm run hide_run'>178</p>
<p class='stm run hide_run'>179</p>
<p class='stm run hide_run'>180</p>
<p class='stm run hide_run'>181</p>
<p class='pln'>182</p>
<p class='pln'>183</p>
<p class='pln'>184</p>
<p class='pln'>185</p>
<p class='pln'>186</p>
<p class='pln'>187</p>
<p class='pln'>188</p>
<p class='stm mis'>189</p>
<p class='stm run hide_run'>190</p>
<p class='stm mis'>191</p>
<p class='pln'>192</p>
<p class='pln'>193</p>
<p class='pln'>194</p>
<p class='pln'>195</p>
<p class='stm mis'>196</p>
<p class='pln'>197</p>
<p class='stm run hide_run'>198</p>
<p class='pln'>199</p>
<p class='pln'>200</p>
<p class='pln'>201</p>
<p class='pln'>202</p>
<p class='stm mis'>203</p>
<p class='pln'>204</p>
<p class='stm run hide_run'>205</p>
<p class='pln'>206</p>
<p class='pln'>207</p>
<p class='pln'>208</p>
<p class='pln'>209</p>
<p class='stm mis'>210</p>
<p class='pln'>211</p>
<p class='pln'>212</p>
<p class='pln'>213</p>
<p class='stm mis'>214</p>
<p class='pln'>215</p>
<p class='pln'>216</p>
<p class='stm mis'>217</p>
<p class='pln'>218</p>
<p class='pln'>219</p>
<p class='pln'>220</p>
<p class='pln'>221</p>
<p class='stm mis'>222</p>
<p class='pln'>223</p>
<p class='stm mis'>224</p>
<p class='stm mis'>225</p>
<p class='stm mis'>226</p>
<p class='stm mis'>227</p>
<p class='stm mis'>228</p>
<p class='pln'>229</p>
<p class='pln'>230</p>
<p class='pln'>231</p>
<p class='pln'>232</p>
<p class='pln'>233</p>
<p class='pln'>234</p>
<p class='pln'>235</p>
<p class='pln'>236</p>
<p class='pln'>237</p>
<p class='pln'>238</p>
<p class='stm mis'>239</p>
<p class='pln'>240</p>
<p class='pln'>241</p>
<p class='pln'>242</p>
<p class='pln'>243</p>
<p class='pln'>244</p>
<p class='pln'>245</p>
<p class='pln'>246</p>
<p class='pln'>247</p>
<p class='pln'>248</p>
<p class='pln'>249</p>
<p class='pln'>250</p>
<p class='pln'>251</p>
<p class='pln'>252</p>
<p class='stm mis'>253</p>
<p class='stm mis'>254</p>
<p class='stm mis'>255</p>
<p class='stm mis'>256</p>
<p class='stm mis'>257</p>
<p class='stm mis'>258</p>
<p class='stm mis'>259</p>
<p class='stm mis'>260</p>
<p class='stm mis'>261</p>
<p class='stm mis'>262</p>
<p class='pln'>263</p>
<p class='pln'>264</p>
<p class='pln'>265</p>
<p class='pln'>266</p>
<p class='pln'>267</p>
<p class='pln'>268</p>
<p class='pln'>269</p>
<p class='pln'>270</p>
<p class='pln'>271</p>
<p class='pln'>272</p>
<p class='pln'>273</p>
<p class='stm mis'>274</p>
<p class='pln'>275</p>
<p class='pln'>276</p>
<p class='pln'>277</p>
<p class='stm mis'>278</p>
<p class='stm mis'>279</p>
<p class='stm mis'>280</p>
<p class='stm mis'>281</p>
<p class='stm mis'>282</p>
<p class='pln'>283</p>
<p class='stm mis'>284</p>
<p class='stm mis'>285</p>
<p class='stm mis'>286</p>
<p class='stm mis'>287</p>
<p class='stm mis'>288</p>
<p class='stm mis'>289</p>
<p class='pln'>290</p>
<p class='stm mis'>291</p>
<p class='stm mis'>292</p>
<p class='stm mis'>293</p>
<p class='stm mis'>294</p>
<p class='stm mis'>295</p>
<p class='pln'>296</p>
<p class='stm mis'>297</p>
<p class='stm mis'>298</p>
<p class='pln'>299</p>
<p class='stm mis'>300</p>
<p class='pln'>301</p>
<p class='pln'>302</p>
<p class='pln'>303</p>
<p class='pln'>304</p>
<p class='pln'>305</p>
<p class='pln'>306</p>
<p class='pln'>307</p>
<p class='pln'>308</p>
<p class='pln'>309</p>
<p class='pln'>310</p>
<p class='pln'>311</p>
<p class='pln'>312</p>
<p class='pln'>313</p>
<p class='pln'>314</p>
<p class='pln'>315</p>
<p class='stm mis'>316</p>
<p class='pln'>317</p>
<p class='pln'>318</p>
<p class='pln'>319</p>
<p class='stm mis'>320</p>
<p class='stm mis'>321</p>
<p class='stm mis'>322</p>
<p class='stm mis'>323</p>
<p class='stm mis'>324</p>
<p class='stm mis'>325</p>
<p class='stm mis'>326</p>
<p class='stm mis'>327</p>
<p class='stm mis'>328</p>
<p class='stm mis'>329</p>
<p class='stm mis'>330</p>
<p class='stm mis'>331</p>
<p class='stm mis'>332</p>
<p class='stm mis'>333</p>
<p class='stm mis'>334</p>
<p class='stm mis'>335</p>
<p class='stm mis'>336</p>
<p class='stm mis'>337</p>
<p class='stm mis'>338</p>
<p class='stm mis'>339</p>
<p class='stm mis'>340</p>
<p class='stm mis'>341</p>
<p class='pln'>342</p>
<p class='stm mis'>343</p>
<p class='stm mis'>344</p>
<p class='stm mis'>345</p>
<p class='stm mis'>346</p>
<p class='stm mis'>347</p>
<p class='stm mis'>348</p>
<p class='stm mis'>349</p>
<p class='pln'>350</p>
<p class='stm mis'>351</p>
<p class='stm mis'>352</p>
<p class='stm mis'>353</p>
<p class='pln'>354</p>
<p class='stm mis'>355</p>
<p class='stm mis'>356</p>
<p class='stm mis'>357</p>
<p class='stm mis'>358</p>
<p class='stm mis'>359</p>
<p class='stm mis'>360</p>
<p class='stm mis'>361</p>
<p class='stm mis'>362</p>
<p class='stm mis'>363</p>
<p class='stm mis'>364</p>
<p class='stm mis'>365</p>
<p class='stm mis'>366</p>
<p class='stm mis'>367</p>
<p class='pln'>368</p>
<p class='stm mis'>369</p>
<p class='stm mis'>370</p>
<p class='stm mis'>371</p>
<p class='stm mis'>372</p>
<p class='pln'>373</p>
<p class='stm mis'>374</p>
<p class='stm mis'>375</p>
<p class='stm mis'>376</p>
<p class='stm mis'>377</p>
<p class='stm mis'>378</p>
<p class='stm mis'>379</p>
<p class='stm mis'>380</p>
<p class='stm mis'>381</p>
<p class='stm mis'>382</p>
<p class='pln'>383</p>
<p class='stm mis'>384</p>
<p class='stm mis'>385</p>
<p class='stm mis'>386</p>
<p class='pln'>387</p>
<p class='stm mis'>388</p>
<p class='stm mis'>389</p>
<p class='stm mis'>390</p>
<p class='pln'>391</p>
<p class='pln'>392</p>
<p class='pln'>393</p>
<p class='pln'>394</p>
<p class='pln'>395</p>
<p class='pln'>396</p>
<p class='stm mis'>397</p>
<p class='pln'>398</p>
<p class='stm run hide_run'>399</p>
<p class='stm run hide_run'>400</p>
<p class='pln'>401</p>
<p class='pln'>402</p>
<p class='pln'>403</p>
<p class='pln'>404</p>
<p class='pln'>405</p>
<p class='pln'>406</p>
<p class='pln'>407</p>
<p class='pln'>408</p>
<p class='pln'>409</p>
<p class='stm par run hide_run'>410</p>
<p class='pln'>411</p>
<p class='stm mis'>412</p>
<p class='stm mis'>413</p>
<p class='stm mis'>414</p>
<p class='pln'>415</p>
<p class='pln'>416</p>
<p class='stm par run hide_run'>417</p>
<p class='stm run hide_run'>418</p>
<p class='stm run hide_run'>419</p>
<p class='stm run hide_run'>420</p>
<p class='stm run hide_run'>421</p>
<p class='stm run hide_run'>422</p>
<p class='stm par run hide_run'>423</p>
<p class='stm mis'>424</p>
<p class='stm par run hide_run'>425</p>
<p class='stm mis'>426</p>
<p class='stm mis'>427</p>
<p class='stm mis'>428</p>
<p class='stm mis'>429</p>
<p class='stm mis'>430</p>
<p class='pln'>431</p>
<p class='stm mis'>432</p>
<p class='pln'>433</p>
<p class='stm run hide_run'>434</p>
<p class='pln'>435</p>
<p class='stm par run hide_run'>436</p>
<p class='stm mis'>437</p>
<p class='stm run hide_run'>438</p>
<p class='pln'>439</p>
<p class='pln'>440</p>
<p class='pln'>441</p>
<p class='stm mis'>442</p>
<p class='stm mis'>443</p>
<p class='pln'>444</p>
<p class='stm mis'>445</p>
<p class='stm mis'>446</p>
<p class='pln'>447</p>
<p class='stm mis'>448</p>
<p class='stm mis'>449</p>
<p class='stm mis'>450</p>
<p class='pln'>451</p>
<p class='pln'>452</p>
<p class='stm mis'>453</p>
<p class='pln'>454</p>
<p class='pln'>455</p>
<p class='stm par run hide_run'>456</p>
<p class='stm run hide_run'>457</p>
<p class='stm run hide_run'>458</p>
<p class='stm mis'>459</p>
<p class='stm mis'>460</p>
<p class='pln'>461</p>
<p class='stm mis'>462</p>
<p class='stm run hide_run'>463</p>
<p class='pln'>464</p>
<p class='pln'>465</p>
<p class='stm mis'>466</p>
<p class='pln'>467</p>
<p class='stm mis'>468</p>
<p class='pln'>469</p>
<p class='pln'>470</p>
<p class='stm mis'>471</p>
<p class='pln'>472</p>
<p class='pln'>473</p>
<p class='stm mis'>474</p>
<p class='stm mis'>475</p>
<p class='stm mis'>476</p>
<p class='stm mis'>477</p>
<p class='stm mis'>478</p>
<p class='stm mis'>479</p>
<p class='stm mis'>480</p>
<p class='stm mis'>481</p>
<p class='stm mis'>482</p>
<p class='pln'>483</p>
<p class='pln'>484</p>
<p class='stm mis'>485</p>
<p class='pln'>486</p>
<p class='pln'>487</p>
<p class='stm mis'>488</p>
<p class='stm mis'>489</p>
<p class='stm mis'>490</p>
<p class='pln'>491</p>
<p class='stm mis'>492</p>
<p class='pln'>493</p>
<p class='stm mis'>494</p>
<p class='stm mis'>495</p>
<p class='stm mis'>496</p>
<p class='stm mis'>497</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'># Module &#39;ntpath&#39; -- common operations on WinNT/Win95 pathnames</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='str'>&quot;&quot;&quot;Common pathname manipulations, WindowsNT/95 version.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>Instead of importing this module directly, import os and refer to this</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>module as os.path.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>os</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>sys</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>stat</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>genericpath</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>import</span> <span class='nam'>warnings</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>from</span> <span class='nam'>genericpath</span> <span class='key'>import</span> <span class='op'>*</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>__all__</span> <span class='op'>=</span> <span class='op'>[</span><span class='str'>&quot;normcase&quot;</span><span class='op'>,</span><span class='str'>&quot;isabs&quot;</span><span class='op'>,</span><span class='str'>&quot;join&quot;</span><span class='op'>,</span><span class='str'>&quot;splitdrive&quot;</span><span class='op'>,</span><span class='str'>&quot;split&quot;</span><span class='op'>,</span><span class='str'>&quot;splitext&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;basename&quot;</span><span class='op'>,</span><span class='str'>&quot;dirname&quot;</span><span class='op'>,</span><span class='str'>&quot;commonprefix&quot;</span><span class='op'>,</span><span class='str'>&quot;getsize&quot;</span><span class='op'>,</span><span class='str'>&quot;getmtime&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;getatime&quot;</span><span class='op'>,</span><span class='str'>&quot;getctime&quot;</span><span class='op'>,</span> <span class='str'>&quot;islink&quot;</span><span class='op'>,</span><span class='str'>&quot;exists&quot;</span><span class='op'>,</span><span class='str'>&quot;lexists&quot;</span><span class='op'>,</span><span class='str'>&quot;isdir&quot;</span><span class='op'>,</span><span class='str'>&quot;isfile&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;ismount&quot;</span><span class='op'>,</span><span class='str'>&quot;walk&quot;</span><span class='op'>,</span><span class='str'>&quot;expanduser&quot;</span><span class='op'>,</span><span class='str'>&quot;expandvars&quot;</span><span class='op'>,</span><span class='str'>&quot;normpath&quot;</span><span class='op'>,</span><span class='str'>&quot;abspath&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;splitunc&quot;</span><span class='op'>,</span><span class='str'>&quot;curdir&quot;</span><span class='op'>,</span><span class='str'>&quot;pardir&quot;</span><span class='op'>,</span><span class='str'>&quot;sep&quot;</span><span class='op'>,</span><span class='str'>&quot;pathsep&quot;</span><span class='op'>,</span><span class='str'>&quot;defpath&quot;</span><span class='op'>,</span><span class='str'>&quot;altsep&quot;</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='str'>&quot;extsep&quot;</span><span class='op'>,</span><span class='str'>&quot;devnull&quot;</span><span class='op'>,</span><span class='str'>&quot;realpath&quot;</span><span class='op'>,</span><span class='str'>&quot;supports_unicode_filenames&quot;</span><span class='op'>,</span><span class='str'>&quot;relpath&quot;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># strings representing various path-related bits and pieces</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>curdir</span> <span class='op'>=</span> <span class='str'>&#39;.&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>pardir</span> <span class='op'>=</span> <span class='str'>&#39;..&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>extsep</span> <span class='op'>=</span> <span class='str'>&#39;.&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>sep</span> <span class='op'>=</span> <span class='str'>&#39;\\&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>pathsep</span> <span class='op'>=</span> <span class='str'>&#39;;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>altsep</span> <span class='op'>=</span> <span class='str'>&#39;/&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>defpath</span> <span class='op'>=</span> <span class='str'>&#39;.;C:\\bin&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>if</span> <span class='str'>&#39;ce&#39;</span> <span class='key'>in</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>builtin_module_names</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>defpath</span> <span class='op'>=</span> <span class='str'>&#39;\\Windows&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>elif</span> <span class='str'>&#39;os2&#39;</span> <span class='key'>in</span> <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>builtin_module_names</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># OS/2 w/ VACPP</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>altsep</span> <span class='op'>=</span> <span class='str'>&#39;/&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>devnull</span> <span class='op'>=</span> <span class='str'>&#39;nul&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Normalize the case of a pathname and map slashes to backslashes.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Other normalizations (such as optimizing &#39;../&#39; away) are not done</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># (this is done by normpath).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>normcase</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Normalize case of pathname.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Makes all characters lowercase and all slashes into backslashes.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>s</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='str'>&quot;/&quot;</span><span class='op'>,</span> <span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Return whether a path is absolute.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Trivial in Posix, harder on the Mac or MS-DOS.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># For DOS it is absolute if it starts with a slash or backslash (current</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># volume), or if a pathname after the volume letter and colon / UNC resource</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># starts with a slash or backslash.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>isabs</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test whether a path is absolute&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>s</span> <span class='op'>=</span> <span class='nam'>splitdrive</span><span class='op'>(</span><span class='nam'>s</span><span class='op'>)</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>s</span> <span class='op'>!=</span> <span class='str'>&#39;&#39;</span> <span class='key'>and</span> <span class='nam'>s</span><span class='op'>[</span><span class='op'>:</span><span class='num'>1</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&#39;/\\&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Join two (or more) paths.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>a</span><span class='op'>,</span> <span class='op'>*</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Join two or more pathname components, inserting &quot;\\&quot; as needed.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; If any component is an absolute path, all previous path components</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; will be discarded.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>a</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>b</span> <span class='key'>in</span> <span class='nam'>p</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>b_wins</span> <span class='op'>=</span> <span class='num'>0</span>&nbsp; <span class='com'># set to 1 iff b makes path irrelevant</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span> <span class='op'>==</span> <span class='str'>&quot;&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>b_wins</span> <span class='op'>=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>isabs</span><span class='op'>(</span><span class='nam'>b</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># This probably wipes out path so far.&nbsp; However, it&#39;s more</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># complicated if path begins with a drive letter:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp;&nbsp; 1. join(&#39;c:&#39;, &#39;/a&#39;) == &#39;c:/a&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp;&nbsp; 2. join(&#39;c:/&#39;, &#39;/a&#39;) == &#39;c:/a&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># But</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp;&nbsp; 3. join(&#39;c:/a&#39;, &#39;/b&#39;) == &#39;/b&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp;&nbsp; 4. join(&#39;c:&#39;, &#39;d:/&#39;) = &#39;d:/&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp;&nbsp; 5. join(&#39;c:/&#39;, &#39;d:/&#39;) = &#39;d:/&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span> <span class='op'>!=</span> <span class='str'>&quot;:&quot;</span> <span class='key'>or</span> <span class='nam'>b</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&quot;:&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Path doesn&#39;t start with a drive letter, or cases 4 and 5.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>b_wins</span> <span class='op'>=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Else path has a drive letter, and b doesn&#39;t but is absolute.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span> <span class='op'>&gt;</span> <span class='num'>3</span> <span class='key'>or</span> <span class='op'>(</span><span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span> <span class='op'>==</span> <span class='num'>3</span> <span class='key'>and</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class='nam'>path</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='key'>not</span> <span class='key'>in</span> <span class='str'>&quot;/\\&quot;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># case 3</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>b_wins</span> <span class='op'>=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>b_wins</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>b</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># Join, and ensure there&#39;s a separator.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>assert</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span> <span class='op'>&gt;</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&quot;/\\&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>b</span> <span class='key'>and</span> <span class='nam'>b</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&quot;/\\&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='nam'>b</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='nam'>b</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&quot;:&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='nam'>b</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>b</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>b</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&quot;/\\&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='nam'>b</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='str'>&quot;\\&quot;</span> <span class='op'>+</span> <span class='nam'>b</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># path is not empty and does not end with a backslash,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># but b is empty; since, e.g., split(&#39;a/&#39;) produces</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># (&#39;a&#39;, &#39;&#39;), it&#39;s best if join() adds a backslash in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># this case.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>+=</span> <span class='str'>&#39;\\&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Split a path in a drive specification (a drive letter followed by a</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># colon) and the path specification.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># It is always true that drivespec + pathspec == p</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>splitdrive</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Split a pathname into drive and path specifiers. Returns a 2-tuple</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;(drive,path)&quot;;&nbsp; either part may be empty&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;:&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>2</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='nam'>p</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Parse UNC paths</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>splitunc</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Split a pathname into UNC mount point and relative path specifiers.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Return a 2-tuple (unc, rest); either part may be empty.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; If unc is not empty, it has the form &#39;//host/mount&#39; (or similar</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; using backslashes).&nbsp; unc+rest is always the input path.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Paths containing drive letters never have an UNC part.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;:&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='nam'>p</span> <span class='com'># Drive letter present</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>firstTwo</span> <span class='op'>=</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>:</span><span class='num'>2</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>firstTwo</span> <span class='op'>==</span> <span class='str'>&#39;//&#39;</span> <span class='key'>or</span> <span class='nam'>firstTwo</span> <span class='op'>==</span> <span class='str'>&#39;\\\\&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># is a UNC path:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># vvvvvvvvvvvvvvvvvvvv equivalent to drive letter</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># \\machine\mountpoint\directories...</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; directory ^^^^^^^^^^^^^^^</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>normp</span> <span class='op'>=</span> <span class='nam'>normcase</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>normp</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='str'>&#39;\\&#39;</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>index</span> <span class='op'>==</span> <span class='op'>-</span><span class='num'>1</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='com'>##raise RuntimeError, &#39;illegal UNC path: &quot;&#39; + p + &#39;&quot;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='op'>(</span><span class='str'>&quot;&quot;</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>normp</span><span class='op'>.</span><span class='nam'>find</span><span class='op'>(</span><span class='str'>&#39;\\&#39;</span><span class='op'>,</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>index</span> <span class='op'>==</span> <span class='op'>-</span><span class='num'>1</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>p</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>index</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='str'>&#39;&#39;</span><span class='op'>,</span> <span class='nam'>p</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Split a path in head (everything up to the last &#39;/&#39;) and tail (the</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># rest).&nbsp; After the trailing &#39;/&#39; is stripped, the invariant</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># join(head, tail) == p holds.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The resulting head won&#39;t end in &#39;/&#39; unless it is the root.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>split</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Split a pathname.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Return tuple (head, tail) where tail is everything after the final slash.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Either part may be empty.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>d</span><span class='op'>,</span> <span class='nam'>p</span> <span class='op'>=</span> <span class='nam'>splitdrive</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># set i to index beyond p&#39;s last slash</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>i</span> <span class='key'>and</span> <span class='nam'>p</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='key'>not</span> <span class='key'>in</span> <span class='str'>&#39;/\\&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>=</span> <span class='nam'>i</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>head</span><span class='op'>,</span> <span class='nam'>tail</span> <span class='op'>=</span> <span class='nam'>p</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>i</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>p</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>:</span><span class='op'>]</span>&nbsp; <span class='com'># now tail has no slashes</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># remove trailing slashes from head, unless it&#39;s all slashes</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>head2</span> <span class='op'>=</span> <span class='nam'>head</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>head2</span> <span class='key'>and</span> <span class='nam'>head2</span><span class='op'>[</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&#39;/\\&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>head2</span> <span class='op'>=</span> <span class='nam'>head2</span><span class='op'>[</span><span class='op'>:</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>head</span> <span class='op'>=</span> <span class='nam'>head2</span> <span class='key'>or</span> <span class='nam'>head</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>d</span> <span class='op'>+</span> <span class='nam'>head</span><span class='op'>,</span> <span class='nam'>tail</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Split a path in root and extension.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The extension is everything starting at the last dot in the last</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># pathname component; the root is everything before that.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># It is always true that root + ext == p.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>splitext</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>genericpath</span><span class='op'>.</span><span class='nam'>_splitext</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>,</span> <span class='nam'>sep</span><span class='op'>,</span> <span class='nam'>altsep</span><span class='op'>,</span> <span class='nam'>extsep</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>splitext</span><span class='op'>.</span><span class='nam'>__doc__</span> <span class='op'>=</span> <span class='nam'>genericpath</span><span class='op'>.</span><span class='nam'>_splitext</span><span class='op'>.</span><span class='nam'>__doc__</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Return the tail (basename) part of a path.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>basename</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Returns the final component of a pathname&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>split</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Return the head (dirname) part of a path.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>dirname</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Returns the directory component of a pathname&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>split</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Is a path a symbolic link?</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># This will always return false on systems where posix.lstat doesn&#39;t exist.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>islink</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test for symbolic link.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; On WindowsNT/95 and OS/2 always returns false</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; &quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>False</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># alias exists to lexists</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>lexists</span> <span class='op'>=</span> <span class='nam'>exists</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Is a path a mount point?&nbsp; Either a root (with or without drive letter)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># or an UNC path with at most a / or \ after the mount point.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>ismount</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test whether a path is a mount point (defined as root of drive)&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>unc</span><span class='op'>,</span> <span class='nam'>rest</span> <span class='op'>=</span> <span class='nam'>splitunc</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>unc</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>rest</span> <span class='key'>in</span> <span class='op'>(</span><span class='str'>&quot;&quot;</span><span class='op'>,</span> <span class='str'>&quot;/&quot;</span><span class='op'>,</span> <span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>p</span> <span class='op'>=</span> <span class='nam'>splitdrive</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>p</span><span class='op'>)</span> <span class='op'>==</span> <span class='num'>1</span> <span class='key'>and</span> <span class='nam'>p</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span> <span class='key'>in</span> <span class='str'>&#39;/\\&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Directory tree walk.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># For each directory under top (including top itself, but excluding</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># &#39;.&#39; and &#39;..&#39;), func(arg, dirname, filenames) is called, where</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># dirname is the name of the directory and filenames is the list</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># of files (and subdirectories etc.) in the directory.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The func may modify the filenames list, to implement a filter,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># or to impose a different order of visiting.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>walk</span><span class='op'>(</span><span class='nam'>top</span><span class='op'>,</span> <span class='nam'>func</span><span class='op'>,</span> <span class='nam'>arg</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Directory tree walk with callback function.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; For each directory in the directory tree rooted at top (including top</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; itself, but excluding &#39;.&#39; and &#39;..&#39;), call func(arg, dirname, fnames).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; dirname is the name of the directory, and fnames a list of the names of</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; the files and subdirectories in dirname (excluding &#39;.&#39; and &#39;..&#39;).&nbsp; func</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; may modify the fnames list in-place (e.g. via del or slice assignment),</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; and walk will only recurse into the subdirectories whose names remain in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; fnames; this can be used to implement a filter, or to impose a specific</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; order of visiting.&nbsp; No semantics are defined for, or required of, arg,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; beyond that arg is always passed to func.&nbsp; It can be used, e.g., to pass</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; a filename pattern, or a mutable object designed to accumulate</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; statistics.&nbsp; Passing None for arg is common.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>warnings</span><span class='op'>.</span><span class='nam'>warnpy3k</span><span class='op'>(</span><span class='str'>&quot;In 3.x, os.path.walk is removed in favor of os.walk.&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>names</span> <span class='op'>=</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>listdir</span><span class='op'>(</span><span class='nam'>top</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>error</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>func</span><span class='op'>(</span><span class='nam'>arg</span><span class='op'>,</span> <span class='nam'>top</span><span class='op'>,</span> <span class='nam'>names</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>name</span> <span class='key'>in</span> <span class='nam'>names</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>name</span> <span class='op'>=</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>top</span><span class='op'>,</span> <span class='nam'>name</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>isdir</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>walk</span><span class='op'>(</span><span class='nam'>name</span><span class='op'>,</span> <span class='nam'>func</span><span class='op'>,</span> <span class='nam'>arg</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Expand paths beginning with &#39;~&#39; or &#39;~user&#39;.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># &#39;~&#39; means $HOME; &#39;~user&#39; means that user&#39;s home directory.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># If the path doesn&#39;t begin with &#39;~&#39;, or if the user or $HOME is unknown,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># the path is returned unchanged (leaving error reporting to whatever</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># function is called with the expanded path as argument).</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># See also module &#39;glob&#39; for expansion of *, ? and [...] in pathnames.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># (A function should also be defined to do full *sh-style environment</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># variable expansion.)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>expanduser</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Expand ~ and ~user constructs.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; If user or $HOME is unknown, do nothing.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='num'>1</span><span class='op'>]</span> <span class='op'>!=</span> <span class='str'>&#39;~&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>i</span><span class='op'>,</span> <span class='nam'>n</span> <span class='op'>=</span> <span class='num'>1</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>i</span> <span class='op'>&lt;</span> <span class='nam'>n</span> <span class='key'>and</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span> <span class='key'>not</span> <span class='key'>in</span> <span class='str'>&#39;/\\&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>=</span> <span class='nam'>i</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='str'>&#39;HOME&#39;</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>userhome</span> <span class='op'>=</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='str'>&#39;HOME&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>elif</span> <span class='str'>&#39;USERPROFILE&#39;</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>userhome</span> <span class='op'>=</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='str'>&#39;USERPROFILE&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>elif</span> <span class='key'>not</span> <span class='str'>&#39;HOMEPATH&#39;</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>drive</span> <span class='op'>=</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='str'>&#39;HOMEDRIVE&#39;</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>KeyError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>drive</span> <span class='op'>=</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>userhome</span> <span class='op'>=</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>drive</span><span class='op'>,</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='str'>&#39;HOMEPATH&#39;</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>i</span> <span class='op'>!=</span> <span class='num'>1</span><span class='op'>:</span> <span class='com'>#~user</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>userhome</span> <span class='op'>=</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>dirname</span><span class='op'>(</span><span class='nam'>userhome</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>path</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='nam'>i</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>userhome</span> <span class='op'>+</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Expand paths containing shell variable substitutions.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># The following rules apply:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - no expansion within single quotes</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - &#39;$$&#39; is translated into &#39;$&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - &#39;%%&#39; is translated into &#39;%&#39; if &#39;%%&#39; are not seen in %var1%%var2%</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - ${varname} is accepted.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - $varname is accepted.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - %varname% is accepted.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp;&nbsp; - varnames can be made out of letters, digits and the characters &#39;_-&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'>#&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; (though is not verifed in the ${varname} and %varname% cases)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># XXX With COMMAND.COM you can use any characters in a variable name,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># XXX except &#39;^|&lt;&gt;=&#39;.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>expandvars</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Expand shell variables of the forms $var, ${var} and %var%.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&nbsp; &nbsp; Unknown variables are left unchanged.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='str'>&#39;$&#39;</span> <span class='key'>not</span> <span class='key'>in</span> <span class='nam'>path</span> <span class='key'>and</span> <span class='str'>&#39;%&#39;</span> <span class='key'>not</span> <span class='key'>in</span> <span class='nam'>path</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>import</span> <span class='nam'>string</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>varchars</span> <span class='op'>=</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>ascii_letters</span> <span class='op'>+</span> <span class='nam'>string</span><span class='op'>.</span><span class='nam'>digits</span> <span class='op'>+</span> <span class='str'>&#39;_-&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>pathlen</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>index</span> <span class='op'>&lt;</span> <span class='nam'>pathlen</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>c</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>c</span> <span class='op'>==</span> <span class='str'>&#39;\&#39;&#39;</span><span class='op'>:</span>&nbsp;&nbsp; <span class='com'># no expansion within single quotes</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>pathlen</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>index</span><span class='op'>(</span><span class='str'>&#39;\&#39;&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;\&#39;&#39;</span> <span class='op'>+</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>ValueError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>pathlen</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>c</span> <span class='op'>==</span> <span class='str'>&#39;%&#39;</span><span class='op'>:</span>&nbsp; <span class='com'># variable or &#39;%&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;%&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>c</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>+</span><span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>pathlen</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>index</span><span class='op'>(</span><span class='str'>&#39;%&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>ValueError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;%&#39;</span> <span class='op'>+</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>pathlen</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>var</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>index</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>var</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='nam'>var</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;%&#39;</span> <span class='op'>+</span> <span class='nam'>var</span> <span class='op'>+</span> <span class='str'>&#39;%&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>c</span> <span class='op'>==</span> <span class='str'>&#39;$&#39;</span><span class='op'>:</span>&nbsp; <span class='com'># variable or &#39;$$&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;$&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>c</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>2</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;{&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>+</span><span class='num'>2</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>pathlen</span> <span class='op'>=</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>index</span><span class='op'>(</span><span class='str'>&#39;}&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>var</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='nam'>index</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>var</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='nam'>var</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;${&#39;</span> <span class='op'>+</span> <span class='nam'>var</span> <span class='op'>+</span> <span class='str'>&#39;}&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>ValueError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;${&#39;</span> <span class='op'>+</span> <span class='nam'>path</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>pathlen</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>var</span> <span class='op'>=</span> <span class='str'>&#39;&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>c</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>c</span> <span class='op'>!=</span> <span class='str'>&#39;&#39;</span> <span class='key'>and</span> <span class='nam'>c</span> <span class='key'>in</span> <span class='nam'>varchars</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>var</span> <span class='op'>=</span> <span class='nam'>var</span> <span class='op'>+</span> <span class='nam'>c</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>c</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='nam'>index</span><span class='op'>:</span><span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>var</span> <span class='key'>in</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>environ</span><span class='op'>[</span><span class='nam'>var</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='str'>&#39;$&#39;</span> <span class='op'>+</span> <span class='nam'>var</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>c</span> <span class='op'>!=</span> <span class='str'>&#39;&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>-</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>res</span> <span class='op'>=</span> <span class='nam'>res</span> <span class='op'>+</span> <span class='nam'>c</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>index</span> <span class='op'>=</span> <span class='nam'>index</span> <span class='op'>+</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>res</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Previously, this function also truncated pathnames to 8+3 format,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># but as this module is called &quot;ntpath&quot;, that&#39;s obviously wrong!</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>normpath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Normalize path, eliminating double slashes, etc.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>replace</span><span class='op'>(</span><span class='str'>&quot;/&quot;</span><span class='op'>,</span> <span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>prefix</span><span class='op'>,</span> <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>splitdrive</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># We need to be careful here. If the prefix is empty, and the path starts</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># with a backslash, it could either be an absolute path on the current</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># drive (\dir1\dir2\file) or a UNC filename (\\server\mount\dir1\file). It</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># is therefore imperative NOT to collapse multiple backslashes blindly in</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># that case.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># The code below preserves multiple backslashes when there is no drive</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># letter. This means that the invalid filename \\\a\b is preserved</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># unchanged, where a\\\b is normalised to a\b. It&#39;s not clear that there</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># is any better behaviour for such edge cases.</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>412</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>prefix</span> <span class='op'>==</span> <span class='str'>&#39;&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># No drive letter - preserve initial backslashes</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>path</span><span class='op'>[</span><span class='op'>:</span><span class='num'>1</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&quot;\\&quot;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>prefix</span> <span class='op'>=</span> <span class='nam'>prefix</span> <span class='op'>+</span> <span class='str'>&quot;\\&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>[</span><span class='num'>1</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='com'># We have a drive letter - collapse initial backslashes</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>420</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>startswith</span><span class='op'>(</span><span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>prefix</span> <span class='op'>=</span> <span class='nam'>prefix</span> <span class='op'>+</span> <span class='str'>&quot;\\&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>lstrip</span><span class='op'>(</span><span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>comps</span> <span class='op'>=</span> <span class='nam'>path</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>=</span> <span class='num'>0</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>while</span> <span class='nam'>i</span> <span class='op'>&lt;</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>comps</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>424</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span> <span class='key'>in</span> <span class='op'>(</span><span class='str'>&#39;.&#39;</span><span class='op'>,</span> <span class='str'>&#39;&#39;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>426</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span> <span class='op'>==</span> <span class='str'>&#39;..&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>i</span> <span class='op'>&gt;</span> <span class='num'>0</span> <span class='key'>and</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>-</span><span class='num'>1</span><span class='op'>]</span> <span class='op'>!=</span> <span class='str'>&#39;..&#39;</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>-</span><span class='num'>1</span><span class='op'>:</span><span class='nam'>i</span><span class='op'>+</span><span class='num'>1</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>-=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>elif</span> <span class='nam'>i</span> <span class='op'>==</span> <span class='num'>0</span> <span class='key'>and</span> <span class='nam'>prefix</span><span class='op'>.</span><span class='nam'>endswith</span><span class='op'>(</span><span class='str'>&quot;\\&quot;</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>del</span> <span class='nam'>comps</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># If the path is now empty, substitute &#39;.&#39;</span><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>437</span>&nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>prefix</span> <span class='key'>and</span> <span class='key'>not</span> <span class='nam'>comps</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>comps</span><span class='op'>.</span><span class='nam'>append</span><span class='op'>(</span><span class='str'>&#39;.&#39;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>prefix</span> <span class='op'>+</span> <span class='str'>&quot;\\&quot;</span><span class='op'>.</span><span class='nam'>join</span><span class='op'>(</span><span class='nam'>comps</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Return an absolute path.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>from</span> <span class='nam'>nt</span> <span class='key'>import</span> <span class='nam'>_getfullpathname</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>except</span> <span class='nam'>ImportError</span><span class='op'>:</span> <span class='com'># not running on Windows - mock up something sensible</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>abspath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Return the absolute version of a path.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>isabs</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>join</span><span class='op'>(</span><span class='nam'>os</span><span class='op'>.</span><span class='nam'>getcwd</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>normpath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='key'>else</span><span class='op'>:</span>&nbsp; <span class='com'># use native Windows method on Windows</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>abspath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Return the absolute version of a path.&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm par run hide_run'><span class='annotate' title='no jump to this line number'>462</span>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>path</span><span class='op'>:</span> <span class='com'># Empty path must return current working directory.</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>_getfullpathname</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>WindowsError</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>pass</span> <span class='com'># Bad path - return unchanged.</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>path</span> <span class='op'>=</span> <span class='nam'>os</span><span class='op'>.</span><span class='nam'>getcwd</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>normpath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># realpath is a no-op on systems without islink support</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>realpath</span> <span class='op'>=</span> <span class='nam'>abspath</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># Win9x family and earlier have no Unicode filename support.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='nam'>supports_unicode_filenames</span> <span class='op'>=</span> <span class='op'>(</span><span class='nam'>hasattr</span><span class='op'>(</span><span class='nam'>sys</span><span class='op'>,</span> <span class='str'>&quot;getwindowsversion&quot;</span><span class='op'>)</span> <span class='key'>and</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>sys</span><span class='op'>.</span><span class='nam'>getwindowsversion</span><span class='op'>(</span><span class='op'>)</span><span class='op'>[</span><span class='num'>3</span><span class='op'>]</span> <span class='op'>&gt;=</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'><span class='key'>def</span> <span class='nam'>relpath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>,</span> <span class='nam'>start</span><span class='op'>=</span><span class='nam'>curdir</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Return a relative version of a path&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>path</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>ValueError</span><span class='op'>(</span><span class='str'>&quot;no path specified&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>start_list</span> <span class='op'>=</span> <span class='nam'>abspath</span><span class='op'>(</span><span class='nam'>start</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='nam'>sep</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>path_list</span> <span class='op'>=</span> <span class='nam'>abspath</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='op'>.</span><span class='nam'>split</span><span class='op'>(</span><span class='nam'>sep</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>start_list</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>!=</span> <span class='nam'>path_list</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>unc_path</span><span class='op'>,</span> <span class='nam'>rest</span> <span class='op'>=</span> <span class='nam'>splitunc</span><span class='op'>(</span><span class='nam'>path</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>unc_start</span><span class='op'>,</span> <span class='nam'>rest</span> <span class='op'>=</span> <span class='nam'>splitunc</span><span class='op'>(</span><span class='nam'>start</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>bool</span><span class='op'>(</span><span class='nam'>unc_path</span><span class='op'>)</span> <span class='op'>^</span> <span class='nam'>bool</span><span class='op'>(</span><span class='nam'>unc_start</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>ValueError</span><span class='op'>(</span><span class='str'>&quot;Cannot mix UNC and non-UNC paths (%s and %s)&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='op'>%</span> <span class='op'>(</span><span class='nam'>path</span><span class='op'>,</span> <span class='nam'>start</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>raise</span> <span class='nam'>ValueError</span><span class='op'>(</span><span class='str'>&quot;path is on drive %s, start on drive %s&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='op'>%</span> <span class='op'>(</span><span class='nam'>path_list</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>,</span> <span class='nam'>start_list</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='com'># Work out how much of the filepath is shared by start and path.</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>i</span> <span class='key'>in</span> <span class='nam'>range</span><span class='op'>(</span><span class='nam'>min</span><span class='op'>(</span><span class='nam'>len</span><span class='op'>(</span><span class='nam'>start_list</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>path_list</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>if</span> <span class='nam'>start_list</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span> <span class='op'>!=</span> <span class='nam'>path_list</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>]</span><span class='op'>.</span><span class='nam'>lower</span><span class='op'>(</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>break</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='key'>else</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>i</span> <span class='op'>+=</span> <span class='num'>1</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='nam'>rel_list</span> <span class='op'>=</span> <span class='op'>[</span><span class='nam'>pardir</span><span class='op'>]</span> <span class='op'>*</span> <span class='op'>(</span><span class='nam'>len</span><span class='op'>(</span><span class='nam'>start_list</span><span class='op'>)</span><span class='op'>-</span><span class='nam'>i</span><span class='op'>)</span> <span class='op'>+</span> <span class='nam'>path_list</span><span class='op'>[</span><span class='nam'>i</span><span class='op'>:</span><span class='op'>]</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>if</span> <span class='key'>not</span> <span class='nam'>rel_list</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>curdir</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; <span class='key'>return</span> <span class='nam'>join</span><span class='op'>(</span><span class='op'>*</span><span class='nam'>rel_list</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
